<?php
include 'daemon.php';

$mEmailQueue = new EmailQueue_model();
$email = $mEmailQueue->get();
if(!$email) exit();


include SERVER_PATH.'/extend/Email.php';
$mailer = new Email();
$result = $mailer->send($email['to'], $email['subject'], $email['content']);

//失败重试一次
if(!$result) {
	$result = $mailer->send($email['to'], $email['subject'], $email['content']);
}

if(!$result) {
	//失败写日志
	Log::write(serialize($email));exit();
}

//成功则删除该邮件
$result = $mEmailQueue->delete($email['id']);

if(!$result) {
	//失败写日志
	Log::write('删除邮件'.$email['id'].'失败');exit();
}